﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace CamDo.BUL
{
        public class Validator
        {
            public static bool EmptyValue(string s)
            {
                //return true if s is null string
                return (s.Trim() == null || s.Trim().Length == 0);
            }
            public static bool IsValidEmail(string strIn)
            {
                // Return true if strIn is in valid e-mail format.
                return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
            }
            public static bool IsAlpha(string s)
            {
                if (!EmptyValue(s))
                {
                    char[] chars = s.ToCharArray();
                    foreach (char c in chars)
                        if (Regex.IsMatch(c.ToString(), @"[^A-Za-z]"))
                            return false;
                    return true;
                }
                return false;
            }
            public static bool CharInRange(char c, char min, char max)
            {
                return (c >= min && c <= max);
            }
            public static bool IsNumeric(string s)
            {
                if (!EmptyValue(s))
                {
                    char[] chars = s.ToCharArray();
                    foreach (char c in chars)
                        if (Regex.IsMatch(c.ToString(), @"[^0-9]"))
                            return false;
                    return true;
                }
                return false;
            }
            public static bool NumInRange(int i, int min, int max)
            {
                return (i >= min && i <= max);
            }
            public static bool IsAlphaNumeric(string s)
            {
                if (!EmptyValue(s))
                {
                    char[] chars = s.ToCharArray();
                    foreach (char c in chars)
                        if (Regex.IsMatch(c.ToString(), @"[^A-Za-z0-9]"))
                            return false;
                    return true;
                }
                return false;
            }
            public static bool IsInSize(string s, uint min, uint max)
            {
                if (!EmptyValue(s))
                    return (s.Trim().Length >= min && s.Trim().Length <= max);
                return false;
            }
            


        }
    
}
